<?php
/**********************************************************
  eCode Marketing System
  Version 0.1
  List Campaigns (/admin/list_campaigns.php)
**********************************************************/

// Require configuration
define("FROMSCRIPT", true);
require dirname(__FILE__) . "/../config.php";


// Start session if not already started
session_start();

if(!isset($_SESSION['login_t'])) {

	/* If we're not logged in, take us to the login page and
	ensure the rest of the code isn't run */

	header("Location: /admin/login.php");
	exit;
}

$pagetitle = "List Campaigns (Admin)";
$pageheading = "<a href=\"/admin/index.php\">" . SITE_NAME . " Administration</a> &gt; List Campaigns";
$page_content = "<hr />\n";

if ($campaigns = $db->get_results("SELECT * FROM `" . DB_TBL_PREFIX . "campaigns`")) {
	// Output table of campaigns
	$page_content .= "<table class=\"table-80\">\n";
	$page_content .= "<tr><td>&nbsp;</td><td>Campaign Name <span class=\"smalltext\">(click for offers)</span></td><td>Start Date</td><td>End Date</td><td>Edit</td><td>Delete</td></tr>\n";
	foreach( $campaigns as $campaign ) {
		$page_content .= "<tr><td>" . $campaign->campaign_id . "</td><td><a href=\"list_offers.php?cid=" . $campaign->campaign_id . "\">" . $campaign->campaign_name . "</a></td><td>" . $campaign->start_date . "</td><td>" . $campaign->end_date . "</td><td><a href=\"/admin/campaign_edit.php?cid=" . $campaign->campaign_id . "\"><img src=\"/admin/assets/edit.png\" alt=\"Edit\" /></a></td><td><a href=\"/admin/handler.campaign_delete.php?cid=" . $campaign->campaign_id . "\"><img src=\"/admin/assets/delete.png\" alt=\"Delete\" /></a></td></tr>\n";
	}
	$page_content .= "</table>\n";
} else {
	$page_content .= "<div id=\"error-box\"><span class=\"error\">ERROR</span>: No active campaigns.</div>\n";
}
$page_content .= "<p class=\"centered\"><a href=\"/admin/campaign_add.php\">Add Campaign</a></p>\n";
$page_content .= "<hr />\n";
$page_content .= "<p><a href=\"/admin/index.php\">Back</a> to " . SITE_NAME . " Administration</p>\n";

// Require template
require TEMPLATE_DIR . "/index.php";
?>